package com.ericsson.rm.validator;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import org.springframework.validation.Errors;
import org.springframework.validation.ValidationUtils;

import com.ericsson.rm.form.SearchResourceCommand;

@Component
public class ResourceSearchValidator {
	
	private final static Logger logger = LoggerFactory.getLogger(ResourceSearchValidator.class);
	private final static String CLASS_NAME = ResourceSearchValidator.class.getSimpleName();
	
	public boolean supports(Class clazz) {
		return SearchResourceCommand.class.isAssignableFrom(clazz);
	}

	public void validate(Object target, Errors errors) {
		final String METHOD_NAME = CLASS_NAME + ".validate() ";
		if(logger.isDebugEnabled()){
			logger.debug(METHOD_NAME+"entering...");
		}
		
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "fromDate", "required.fromDate", "Field name is required.");
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "toDate", "required.toDate", "Field name is required.");		
		
	}
}
